package com.iemes.controller.finance;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.controller.index.BaseController;
import com.iemes.entity.FundReturnFormMap;
import com.iemes.mapper.finance.FundReturnMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;
import com.iemes.util.DateUtils;
import com.iemes.util.MyDateUtils;

@RequestMapping("/finance")
@Controller
public class FundReturnOverController extends BaseController {

	
	@Inject
	private FundReturnMapper fundReturnMapper;
	
	@RequestMapping("fundreturnover")
	private String fundreturnover(Model model){
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/finance/receivablesmanagement/fundreturnover_list";
	}
	
	
	@ResponseBody
	@RequestMapping("fundreturnover_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception 
	{
		
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		
		FundReturnFormMap fundreturn=getFormMap(FundReturnFormMap.class);
		List<Map<String,Object>> fundreturns=fundReturnMapper.getFundReturnOverByCondition(fundreturn);
		
		for(Map<String,Object>map:fundreturns){
			//String date1=DateUtils.stringToDate(map.get("signing_time"));
			//System.out.println("date1:"+DateUtils.stringToDate(map.get("signing_time").toString()));
			
			System.out.println(MyDateUtils.intervalTime(map.get("signing_time").toString(),Integer.parseInt(map.get("collection_period").toString())));
			//签订的时间+收款天数再和当前时间对比，计算出超期的天数
			//签订时间
			String overtime=map.get("signing_time").toString();
			//收款期限
			int day=Integer.parseInt(map.get("collection_period").toString());
			map.put("overTime", MyDateUtils.intervalTime(overtime,day));
			
			//总金额-已到账的账款，得出超期金额
			//总金额
			double total=Double.parseDouble(map.get("price").toString());
			//已到账账款
			double price=Double.parseDouble(map.get("thisMonthReceivableDue").toString());
			//超期金额
			double overPrice=total-price;
			map.put("overPrice", overPrice);
			System.out.println("超出金额我操你："+overPrice);
		}
		
		LuogicPaging(pageNow, pageSize, fundreturns);
		return pageView;
	}
	
}
